package com.ruihu.admin.module.business.log.aiimagelog.domain.entity;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.annotation.TableName;
import com.ruihu.admin.common.domain.BaseEntity;
import com.ruihu.admin.module.business.log.aiimagelog.domain.dto.AiImageLogAddDTO;
import com.ruihu.admin.module.business.log.aiimagelog.domain.dto.AiImageLogDTO;
import com.ruihu.admin.module.business.log.aiimagelog.domain.dto.AiImageLogUpdateDTO;
import lombok.Data;

import java.util.Date;
import java.util.Objects;

/**
 * [  ]
 *
 * @author Tony
 * @version 1.0
 * @company 瑞虎（南京）信息技术有限公司
 * @copyright (c)  瑞虎（南京）信息技术有限公司Inc. All rights reserved.
 * @date 2023-01-30 13:54:39
 * @since JDK1.8
 */

@Data
@TableName("t_ai_image_log")
public class AiImageLogEntity extends BaseEntity {


    /**
     * 日志接口ID
     */
    private Long interfaceLogId;

    /**
     * 文件名称
     */
    private String fileName;

    /**
     * 处理结果
     */
    private String result;


    public static AiImageLogEntity convertToAiImageLogEntity(AiImageLogAddDTO addDTO) {
        if (addDTO == null) {
            return null;
        }

        AiImageLogEntity entity = new AiImageLogEntity();
        entity.setInterfaceLogId(addDTO.getInterfaceLogId());
        entity.setFileName(addDTO.getFileName());
        entity.setResult(addDTO.getResult());
        return entity;
    }


    public static AiImageLogEntity convertToAiImageLogEntity(AiImageLogUpdateDTO updateDTO) {
        if (updateDTO == null) {
           return null;
        }

        AiImageLogEntity entity = new AiImageLogEntity();
        entity.setId(updateDTO.getId());
        entity.setInterfaceLogId(updateDTO.getInterfaceLogId());
        entity.setFileName(updateDTO.getFileName());
        entity.setResult(updateDTO.getResult());
        return entity;
    }

    public static AiImageLogEntity convertToAiImageLogEntity(AiImageLogDTO dto) {
        if (dto == null) {
           return null;
        }

        AiImageLogEntity entity = new AiImageLogEntity();
        entity.setId(dto.getId());
        entity.setInterfaceLogId(dto.getInterfaceLogId());
        entity.setFileName(dto.getFileName());
        entity.setResult(dto.getResult());
        entity.setCreateTime(dto.getCreateTime());

        return entity;
    }

    public static AiImageLogEntity copyIgnoreNullAndEmpty(AiImageLogEntity sourceEntity, AiImageLogEntity destEntity) {
        if (Objects.isNull(sourceEntity))
            return destEntity;

        if (Objects.nonNull(sourceEntity.getId())) {
           destEntity.setId(sourceEntity.getId());
        }
        if (Objects.nonNull(sourceEntity.getInterfaceLogId())) {
           destEntity.setInterfaceLogId(sourceEntity.getInterfaceLogId());
        }
        if (StrUtil.isNotEmpty(sourceEntity.getFileName())) {
           destEntity.setFileName(sourceEntity.getFileName());
        }
        if (StrUtil.isNotEmpty(sourceEntity.getResult())) {
           destEntity.setResult(sourceEntity.getResult());
        }
        if (Objects.nonNull(sourceEntity.getCreateTime())) {
            destEntity.setCreateTime(sourceEntity.getCreateTime());
        }
        return destEntity;
    }
}
